<?php
class Phone{
	
	var $id;
	var $phoneNumber;
	var $lastActivty;

	function getPhone($id){
		//recherche dans la BDD et r�cup�re renseigne l'objet selon l'id pass� en param�tre
		include_once 'Util/includeAll.php';
		
		$rq = "select * from phone where id = $id";
		$retour = executeBDD($rq);
		
		if($retour)
		{
			$num_rows = mysql_num_rows($retour);
			while($donnees = mysql_fetch_array($retour))
			{
				$this->lastActivty = $donnees['last_activity'];
				$this->phoneNumber = $donnees['phone_number'];
				$this->id = $id;
			}
			return 1;
		}
		else
		{
			return -1;
		}
	}
	
	function savePhoneinBDD($idUser){
		//sauvegarde l'objet dans la BDD
		
		include_once 'Util/includeAll.php';
		
		$rq = "insert into phone(id_user, phone_number, last_activity) values ($idUser, '".$this->phoneNumber."', NOW())";
		$retour = executeBDD($rq);
		
		if($retour)
		{
			return 1;
		}
		else
		{
			return -1;
		}
		
	}
	
	//TODO a tester
	function MaJLastActivity()
	{
		include_once 'Util/includeAll.php';
		
		$rq = "update phone set last_activity = NOW() where id= ".$this->id;
		$retour = executeBDD($rq);
		
		if($retour)
		{
			return 1;
		}
		else
		{
			return -1;
		}
	}
}
?>